package com.qf.cloud2202.microb;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@RestController
public class MicrobApp {

    public static void main(String[] args) {
        SpringApplication.run(MicrobApp.class);
    }

    @Bean
    public RestTemplate restTemplate(){

        final RestTemplate restTemplate = new RestTemplate();

        return restTemplate;

    }


    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    EurekaClient eurekaClient;

    @GetMapping("/test1")
    public String test1(){

        final InstanceInfo instanceInfo = eurekaClient.getNextServerFromEureka("MICROA", false);

        final String ipAddr = instanceInfo.getIPAddr();
        final int port = instanceInfo.getPort();
        final String hostName = instanceInfo.getHostName();
        final String homePageUrl = instanceInfo.getHomePageUrl();

        System.out.println(ipAddr);
        System.out.println(port);
        System.out.println(hostName);
        System.out.println(homePageUrl);

        return homePageUrl;
    }

}
